#pragma once

#include "Misc/EngineEditorMacros.h"
#include "Object/Object.h"
#include "PieceTable.h"
#include "Path/Path.h"
#include "TextDocument.m.h"

RCLASS()
class RTextDocument : public RObject
{
    ROBJECT

public:
    void SetFilePath(const SPath& InPath );
    SPath GetFilePath() const
    {
        return FilePath;
    }

    static TSharedObjectPtr<RTextDocument> Create(const SPath& InPath);

    SPieceTable& GetPieceTable() 
    {
        return PieceTable;
    }

    bool HasUnsavedData() const;

    void Save();
    
    void Undo(SDocumentPosition& InOutCursorPos);
    void Redo(SDocumentPosition& InOutCursorPos);
    bool CanUndo() const;
    bool CanRedo() const;

protected:
    RFIELD()
    SPath FilePath;

    void InitPieceTable();

    //data structure store the text
    RFIELD()
    SPieceTable PieceTable;



};
